trigger trg_PartyInformation on Party_Information__c (after insert, after update)
{
    Map<ID,ID> partyObjectMap = new Map<Id,ID>();
    
    //ONly Checking the Summation of the Share Profit is not greater than 100...
    
    for(Party_Information__c partyObject : Trigger.New)
    {
        if(Trigger.isInsert)
        {
            if(partyObject.Share_Profit__c != null)
            {
                partyObjectMap.put(partyObject.Id,partyObject.Account__c);
            }
        }
        else if(Trigger.isUpdate)
        {
        	System.debug('');
            if(Trigger.oldMap.get(partyObject.id).Share_Profit__c != partyObject.Share_Profit__c)
            {
                if(partyObject.Share_Profit__c != null)
                {
                    partyObjectMap.put(partyObject.Id,partyObject.Account__c);
                }
            
            }
        }
        
    }
    //Now the lOgic Begins...
    if(partyObjectMap.size() > 0)
    {
        Decimal sharePercentageTotal = 0;
        for(Party_Information__c partyObject : [select id,Account__c,Share_Profit__c FROM Party_Information__c where Account__c =: partyObjectMap.values() AND Share_Profit__c != null ORDER BY Account__c])
        {   
            //System.debug('The Total Party Information Size => 'partyObject.size());
            
            System.debug('The Share Profit Values => '+ partyObject.Share_Profit__c);
            sharePercentageTotal = sharePercentageTotal + partyObject.Share_Profit__c;
            System.debug('The Share Percentage Total => '+ sharePercentageTotal );
            
            if(sharePercentageTotal > 100)
            {
                for(Party_Information__c tempPartyObject : Trigger.new)
                {
                    if(partyObject.Account__c == tempPartyObject.Account__c)
                    {
                        tempPartyObject.Share_Profit__c.adderror('Sum of all the Ownership associated with the Account cannot be more than 100%');
                    }
                }
            }
            
        }
    }
    
    
    
    
    
    
    
}